using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using Common;

namespace Converters
{
	public class DoubleToStringConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value != null && value != DependencyProperty.UnsetValue && value is double)
			{
				return ResultFormat.Format((double)value);
			}
			return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null || value.ToString() == "" || value.ToString() == "-")
			{
				return double.NaN;
			}
			if (value.ToString() == Utility.GetMessage("NoCt"))
			{
				return double.PositiveInfinity;
			}
			return value;
		}
	}
}
